import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ColorConfig } from "../../../resource/ColorConfig";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { OpenRechargeGiftBagConfig } from "../../../resource/OpenRechargeGiftBagConfig";
import { Cache } from "../../../cache/Cache";
import { ItemData } from "../../../resource/info/ItemData";
import { RechargeData } from "./RechargeData";
import { EffectManager } from "../../../manager/EffectManager";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { TOpenRechargeGiftBag } from "../../../../../Message/Db/Tables/TOpenRechargeGiftBag";
type int = number;
//class RechargeActiveItem
    
    export  class RechargeActiveItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._glowYellow = new Object /* flash.filters.GlowFilter */(16776960, 1, 3, 3, 5);
            this.init();
            return;
        }

        public get pwidth(): int
        {
            return this._pwidth;
        }

        public get itemCode(): int
        {
            var loc1=0;
            if (this._info) 
            {
                loc1 = this._info.itemCode;
            }
            return loc1;
        }

        public get value(): int
        {
            var loc1=0;
            if (this._info) 
            {
                loc1 = this._info.value;
            }
            return loc1;
        }

        /* internal  */init(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 90, 135, this, ImagesConst.RechargeBottom);
            var loc1=new GTextFormat("", 12, ColorConfig.instance.getItemColor(4).intColor, true, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._nameBg = ObjCreate.createBg(0, 2, 90, 20, this, ImagesConst.FightingStrgBg);
            this._nameTxt = ObjCreate.createTextField("", 0, 2, 90, 20, this, loc1);
            this._itemBg = ObjCreate.createBg(14, 27, 64, 64, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.move(16, 29);
            this._baseItem.setSize(60, 60);
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            addChild(this._baseItem);
            this._getBtn = ObjCreate.createGButton(Language.getString(20146), 20, 100, 50, 25, this, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._getBtn.enabled = false;
            return;
        }

        protected onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GetOpenRechargeGiftBag, this._info.code));
            }
            return;
        }

        public updateData(arg1: int): void
        {
            var loc1=OpenRechargeGiftBagConfig.instance.getGiftBagInfoByTarget(arg1, 1, Cache.instance.role.activeWorldLevel);
            if (loc1 == null) 
            {
                return;
            }
            this._info = loc1;
            this._nameTxt.text = Language.getStringByParam(20151, loc1.target);
            this._baseItem.itemData = new ItemData(loc1.itemCode);
            this.moneyUpdate();
            return;
        }

        public moneyUpdate(): void
        {
            var loc1=Cache.instance.role.recharge;
            if (loc1 >= this._info.target && !RechargeData.isHadGet(this._info.code)) 
            {
                this._getBtn.enabled = true;
                EffectManager.glowFilterReg(this._getBtn, [this._glowYellow], 0.5, 6, 3, 0);
            }
            return;
        }

        public updateHadGainState(): void
        {
            if (RechargeData.isHadGet(this._info.code)) 
            {
                this._getBtn.enabled = false;
                EffectManager.glowFilterUnReg(this._getBtn);
                this._getBtn.label = Language.getString(20152);
            }
            return;
        }

        public setWidth(arg1: int): void
        {
            this._pwidth = arg1;
            this._bg.width = arg1;
            this._itemBg.x = (arg1 - this._itemBg.width) / 2;
            this._baseItem.x = this._itemBg.x + 2;
            this._nameBg.width = arg1;
            this._nameTxt.width = arg1;
            this._getBtn.x = (arg1 - this._getBtn.width) / 2;
            return;
        }

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_itemBg: ScaleBitmap;

        protected /* var */_nameBg: ScaleBitmap;

        protected /* var */_baseItem: BaseItem;

        protected /* var */_getBtn: GButton;

        protected /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_info: TOpenRechargeGiftBag;

        protected /* var */_pwidth: int=90;

        protected /* var */_glowYellow: Object /* flash.filters.GlowFilter */;
    }
